package com.example.controller;

import com.example.bean.NetInfo;
import com.example.enmu.ErrorEnmu;
import com.example.enmu.ResultCodeEnum;
import com.example.model.SdInfo;
import com.example.model.dto.PageDTO;
import com.example.result.DataResponse;
import com.example.service.CLibrary;
import com.example.service.DeviceService;
import com.example.util.ByteUtil;
import com.example.util.TypeConversionUtil;
import com.sun.jna.ptr.IntByReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/device")
public class DeviceController {

    @Autowired
    DeviceService deviceService;

    /**
     * 分页获取设备列表
     * @return
     */
    @PostMapping("/list")
    public DataResponse list(@RequestBody PageDTO pageDTO){
        return new DataResponse(deviceService.pageList(pageDTO));
    }

    /**
     * 更新网络地址
     * @param sdInfo
     * @return
     */
    @PostMapping("/update")
    public DataResponse updateInfo(@RequestBody SdInfo sdInfo){
        return deviceService.updateInfo(sdInfo);
    }

    /**
     * 开启读卡机
     * @param sdInfo
     * @return
     */
    @PostMapping("/openDevice")
    public DataResponse openDevice(@RequestBody SdInfo sdInfo){
        return deviceService.openDevice(sdInfo);
    }

    /**
     * 关闭读卡机
     * @param sdInfo
     * @return
     */
    @PostMapping("/closeDevice")
    public DataResponse closeDevice(@RequestBody SdInfo sdInfo){
        return deviceService.closeDevice(sdInfo);
    }

    /**
     * 刷新读卡机
     */
    @PostMapping("/refreshDevice")
    public DataResponse refreshDevice(@RequestBody SdInfo sdInfo){
        return deviceService.refreshDevice(sdInfo);
    }
}
